/*
Copyright 2020 The OneFlow Authors. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "oneflow/user/ops/reshape_user_op_util.h"

#include <gtest/gtest.h>

namespace oneflow {
namespace test {

namespace {

std::string NdSbpIn2OutSignaturesToString(
    const std::vector<std::vector<std::pair<int, int>>>& nd_split_in2out_axis_list) {
  std::ostringstream ss;
  ss << "{";
  int i = 0;
  for (const auto& nd_split_axis : nd_split_in2out_axis_list) {
    if (i > 0) { ss << ", "; }
    ss << "{";
    int j = 0;
    for (const auto& split_in2out_axis : nd_split_axis) {
      if (j > 0) { ss << ", "; }
      ss << "{" << split_in2out_axis.first << ", " << split_in2out_axis.second << "}";
      j++;
    }
    ss << "}";
    i++;
  }
  ss << "}";
  return ss.str();
}

std::string NdSbpSignatureGroupsToString(
    const std::vector<std::map<int, std::pair<int, int>>>& nd_sbp_signature_groups) {
  std::ostringstream ss;
  ss << "{";
  int i = 0;
  for (const auto& nd_sbp_sig_group : nd_sbp_signature_groups) {
    if (i > 0) { ss << ", "; }
    ss << "{";
    int j = 0;
    for (const auto& nd_sbp_sig_pair : nd_sbp_sig_group) {
      if (j > 0) { ss << ", "; }
      ss << nd_sbp_sig_pair.first << ": {" << nd_sbp_sig_pair.second.first << ", "
         << nd_sbp_sig_pair.second.second << "}";
      j++;
    }
    ss << "}";
    i++;
  }
  ss << "}";
  return ss.str();
}

void TestEnumerateNdSbpIn2OutSignatures(
    const Shape& in_shape, const Shape& out_shape, const Shape& rank_mesh,
    const std::vector<std::map<int, std::pair<int, int>>>& expected_nd_sbp_in2out_sig_groups,
    const std::vector<std::vector<std::pair<int, int>>>& expected_nd_sbp_in2out_sig_list) {
  std::vector<std::map<int, std::pair<int, int>>> actual_nd_sbp_in2out_sig_groups;
  CHECK_JUST(ReshapeUserOpUtil::EnumerateNdSplitIn2OutAxisGroups(in_shape, out_shape, rank_mesh,
                                                                 &actual_nd_sbp_in2out_sig_groups));
  std::sort(actual_nd_sbp_in2out_sig_groups.begin(), actual_nd_sbp_in2out_sig_groups.end());
  ASSERT_EQ(expected_nd_sbp_in2out_sig_groups.size(), actual_nd_sbp_in2out_sig_groups.size());
  for (size_t i = 0; i < actual_nd_sbp_in2out_sig_groups.size(); ++i) {
    const auto& exp_nd_sbp_sig_group = expected_nd_sbp_in2out_sig_groups[i];
    const auto& act_nd_sbp_sig_group = actual_nd_sbp_in2out_sig_groups[i];
    ASSERT_EQ(exp_nd_sbp_sig_group.size(), act_nd_sbp_sig_group.size());
    for (const auto& act_pair : act_nd_sbp_sig_group) {
      auto exp_it = exp_nd_sbp_sig_group.find(act_pair.first);
      ASSERT_TRUE(exp_it != exp_nd_sbp_sig_group.end());
      ASSERT_EQ(exp_it->second.first, act_pair.second.first);
      ASSERT_EQ(exp_it->second.second, act_pair.second.second);
    }
  }

  std::vector<std::vector<std::pair<int, int>>> actual_nd_sbp_in2out_sig_list;
  CHECK_JUST(ReshapeUserOpUtil::EnumerateNdSbpIn2OutSignatures(in_shape, out_shape, rank_mesh,
                                                               &actual_nd_sbp_in2out_sig_list));
  CHECK_JUST(ReshapeUserOpUtil::FilterNdSbpIn2OutSignatures(in_shape, out_shape, rank_mesh,
                                                            &actual_nd_sbp_in2out_sig_list));
  std::sort(actual_nd_sbp_in2out_sig_list.begin(), actual_nd_sbp_in2out_sig_list.end());
  ASSERT_EQ(expected_nd_sbp_in2out_sig_list.size(), actual_nd_sbp_in2out_sig_list.size());
  for (size_t i = 0; i < actual_nd_sbp_in2out_sig_list.size(); ++i) {
    const auto& exp_nd_sbp_sig = expected_nd_sbp_in2out_sig_list[i];
    const auto& act_nd_sbp_sig = actual_nd_sbp_in2out_sig_list[i];
    ASSERT_EQ(exp_nd_sbp_sig.size(), act_nd_sbp_sig.size());
    for (size_t j = 0; j < act_nd_sbp_sig.size(); ++j) {
      ASSERT_EQ(exp_nd_sbp_sig[j].first, act_nd_sbp_sig[j].first);
      ASSERT_EQ(exp_nd_sbp_sig[j].second, act_nd_sbp_sig[j].second);
    }
  }
}

}  // namespace

using std::pair;

TEST(ReshapeUserOpUtil, EnumerateNdSbpIn2OutSignatures) {
  // clang-format off
  // 2D-split
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {4}, /*out_shape*/ {2, 2}, /*rank_mesh*/ {2, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{0, 1}}},
       {{1, pair{0, 0}}}},
      {{{-2, -2}, {-2, -2}},
       {{-2, -2}, {-1, -1}},
       {{-2, -2}, {0, 0}},
       {{-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}},
       {{-1, -1}, {0, 0}},
       {{0, 0}, {-2, -2}},
       {{0, 0}, {-1, -1}},
       {{0, 0}, {0, 1}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {12}, /*out_shape*/ {2, 2, 3}, /*rank_mesh*/ {2, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{0, 1}}},
       {{1, pair{0, 0}}}},
      {{{-2, -2}, {-2, -2}},
       {{-2, -2}, {-1, -1}},
       {{-2, -2}, {0, 0}},
       {{-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}},
       {{-1, -1}, {0, 0}},
       {{0, 0}, {-2, -2}},
       {{0, 0}, {-1, -1}},
       {{0, 0}, {0, 1}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {2, 4}, /*out_shape*/ {8}, /*rank_mesh*/ {2, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{1, 0}}},
       {{1, pair{0, 0}}}},
      {{{-2, -2}, {-2, -2}},
       {{-2, -2}, {-1, -1}},
       {{-2, -2}, {0, 0}},
       {{-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}},
       {{-1, -1}, {0, 0}},
       {{0, 0}, {-2, -2}},
       {{0, 0}, {-1, -1}},
       {{0, 0}, {1, 0}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {2, 1, 4}, /*out_shape*/ {8}, /*rank_mesh*/ {2, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{2, 0}}},
       {{1, pair{0, 0}}}},
      {{{-2, -2}, {-2, -2}},
       {{-2, -2}, {-1, -1}},
       {{-2, -2}, {0, 0}},
       {{-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}},
       {{-1, -1}, {0, 0}},
       {{0, 0}, {-2, -2}},
       {{0, 0}, {-1, -1}},
       {{0, 0}, {2, 0}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {8, 2}, /*out_shape*/ {2, 4, 2}, /*rank_mesh*/ {2, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{0, 1}}},
       {{0, pair{1, 2}}},
       {{1, pair{0, 0}}},
       {{1, pair{1, 2}}}},
      {{{-2, -2}, {-2, -2}},
       {{-2, -2}, {-1, -1}},
       {{-2, -2}, {0, 0}},
       {{-2, -2}, {1, 2}},
       {{-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}},
       {{-1, -1}, {0, 0}},
       {{-1, -1}, {1, 2}},
       {{0, 0}, {-2, -2}},
       {{0, 0}, {-1, -1}},
       {{0, 0}, {0, 1}},
       {{0, 0}, {1, 2}},
       {{1, 2}, {-2, -2}},
       {{1, 2}, {-1, -1}},
       {{1, 2}, {0, 0}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {8, 1, 2}, /*out_shape*/ {2, 1, 4, 2}, /*rank_mesh*/ {2, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{0, 2}}},
       {{0, pair{2, 3}}},
       {{1, pair{0, 0}}},
       {{1, pair{2, 3}}},},
      {{{-2, -2}, {-2, -2}},
       {{-2, -2}, {-1, -1}},
       {{-2, -2}, {0, 0}},
       {{-2, -2}, {2, 3}},
       {{-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}},
       {{-1, -1}, {0, 0}},
       {{-1, -1}, {2, 3}},
       {{0, 0}, {-2, -2}},
       {{0, 0}, {-1, -1}},
       {{0, 0}, {0, 2}},
       {{0, 0}, {2, 3}},
       {{2, 3}, {-2, -2}},
       {{2, 3}, {-1, -1}},
       {{2, 3}, {0, 0}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {3, 2, 3, 5}, /*out_shape*/ {3, 30}, /*rank_mesh*/ {2, 3},
      {{{0, pair{1, 1}}},
       {{0, pair{1, 1}}, {1, pair{2, 1}}},
       {{1, pair{0, 0}}}},
      {{{-2, -2}, {-2, -2}},
       {{-2, -2}, {-1, -1}},
       {{-2, -2}, {0, 0}},
       {{-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}},
       {{-1, -1}, {0, 0}},
       {{1, 1}, {-2, -2}},
       {{1, 1}, {-1, -1}},
       {{1, 1}, {0, 0}},
       {{1, 1}, {2, 1}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {2, 4}, /*out_shape*/ {4, 2}, /*rank_mesh*/ {2, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{1, 0}}},
       {{1, pair{0, 0}}}},
      {{{-2, -2}, {-2, -2}},
       {{-2, -2}, {-1, -1}},
       {{-2, -2}, {0, 0}},
       {{-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}},
       {{-1, -1}, {0, 0}},
       {{0, 0}, {-2, -2}},
       {{0, 0}, {-1, -1}},
       {{0, 0}, {1, 0}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {4, 2}, /*out_shape*/ {2, 4}, /*rank_mesh*/ {2, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{0, 1}}},
       {{1, pair{0, 0}}}},
      {{{-2, -2}, {-2, -2}},
       {{-2, -2}, {-1, -1}},
       {{-2, -2}, {0, 0}},
       {{-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}},
       {{-1, -1}, {0, 0}},
       {{0, 0}, {-2, -2}},
       {{0, 0}, {-1, -1}},
       {{0, 0}, {0, 1}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {4, 3}, /*out_shape*/ {3, 4}, /*rank_mesh*/ {2, 3}, 
      {},
      {{{-2, -2}, {-2, -2}}, 
       {{-2, -2}, {-1, -1}}, 
       {{-1, -1}, {-2, -2}}, 
       {{-1, -1}, {-1, -1}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {2, 6}, /*out_shape*/ {4, 3}, /*rank_mesh*/ {2, 3},
      {{{0, pair{0, 0}}}},
      {{{-2, -2}, {-2, -2}},
       {{-2, -2}, {-1, -1}},
       {{-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}},
       {{0, 0}, {-2, -2}},
       {{0, 0}, {-1, -1}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {2, 2, 5, 4}, /*out_shape*/ {4, 5, 2, 2}, /*rank_mesh*/ {2, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{1, 0}}},
       {{0, pair{3, 2}}},
       {{0, pair{3, 2}}, {1, pair{3, 3}}},
       {{1, pair{0, 0}}},
       {{1, pair{3, 2}}}},
      {{{-2, -2}, {-2, -2}},
       {{-2, -2}, {-1, -1}},
       {{-2, -2}, {0, 0}},
       {{-2, -2}, {3, 2}},
       {{-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}},
       {{-1, -1}, {0, 0}},
       {{-1, -1}, {3, 2}},
       {{0, 0}, {-2, -2}},
       {{0, 0}, {-1, -1}},
       {{0, 0}, {1, 0}},
       {{0, 0}, {3, 2}},
       {{3, 2}, {-2, -2}},
       {{3, 2}, {-1, -1}},
       {{3, 2}, {0, 0}},
       {{3, 2}, {3, 3}}});
  // 3D-split
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {24}, /*out_shape*/ {2, 4, 3}, /*rank_mesh*/ {2, 2, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{0, 1}}},
       {{0, pair{0, 0}}, {1, pair{0, 1}}, {2, pair{0, 1}}},
       {{0, pair{0, 0}}, {2, pair{0, 1}}},
       {{1, pair{0, 0}}},
       {{1, pair{0, 0}}, {2, pair{0, 1}}},
       {{2, pair{0, 0}}}},
      {{{-2, -2}, {-2, -2}, {-2, -2}}, {{-2, -2}, {-2, -2}, {-1, -1}}, {{-2, -2}, {-2, -2}, {0, 0}},
       {{-2, -2}, {-1, -1}, {-2, -2}}, {{-2, -2}, {-1, -1}, {-1, -1}}, {{-2, -2}, {-1, -1}, {0, 0}},
       {{-2, -2}, {0, 0}, {-2, -2}},   {{-2, -2}, {0, 0}, {-1, -1}},   {{-2, -2}, {0, 0}, {0, 1}},
       {{-1, -1}, {-2, -2}, {-2, -2}}, {{-1, -1}, {-2, -2}, {-1, -1}}, {{-1, -1}, {-2, -2}, {0, 0}},
       {{-1, -1}, {-1, -1}, {-2, -2}}, {{-1, -1}, {-1, -1}, {-1, -1}}, {{-1, -1}, {-1, -1}, {0, 0}},
       {{-1, -1}, {0, 0}, {-2, -2}},   {{-1, -1}, {0, 0}, {-1, -1}},   {{-1, -1}, {0, 0}, {0, 1}},
       {{0, 0}, {-2, -2}, {-2, -2}},   {{0, 0}, {-2, -2}, {-1, -1}},   {{0, 0}, {-2, -2}, {0, 1}},
       {{0, 0}, {-1, -1}, {-2, -2}},   {{0, 0}, {-1, -1}, {-1, -1}},   {{0, 0}, {-1, -1}, {0, 1}},
       {{0, 0}, {0, 1}, {-2, -2}},     {{0, 0}, {0, 1}, {-1, -1}},     {{0, 0}, {0, 1}, {0, 1}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {3, 24}, /*out_shape*/ {3, 2, 2, 6}, /*rank_mesh*/ {2, 2, 2},
      {{{0, pair{1, 1}}},
       {{0, pair{1, 1}}, {1, pair{1, 2}}},
       {{0, pair{1, 1}}, {1, pair{1, 2}}, {2, pair{1, 3}}},
       {{0, pair{1, 1}}, {2, pair{1, 2}}},
       {{1, pair{1, 1}}},
       {{1, pair{1, 1}}, {2, pair{1, 2}}},
       {{2, pair{1, 1}}}},
      {{{-2, -2}, {-2, -2}, {-2, -2}}, {{-2, -2}, {-2, -2}, {-1, -1}}, {{-2, -2}, {-2, -2}, {1, 1}},
       {{-2, -2}, {-1, -1}, {-2, -2}}, {{-2, -2}, {-1, -1}, {-1, -1}}, {{-2, -2}, {-1, -1}, {1, 1}},
       {{-2, -2}, {1, 1}, {-2, -2}},   {{-2, -2}, {1, 1}, {-1, -1}},   {{-2, -2}, {1, 1}, {1, 2}},
       {{-1, -1}, {-2, -2}, {-2, -2}}, {{-1, -1}, {-2, -2}, {-1, -1}}, {{-1, -1}, {-2, -2}, {1, 1}},
       {{-1, -1}, {-1, -1}, {-2, -2}}, {{-1, -1}, {-1, -1}, {-1, -1}}, {{-1, -1}, {-1, -1}, {1, 1}},
       {{-1, -1}, {1, 1}, {-2, -2}},   {{-1, -1}, {1, 1}, {-1, -1}},   {{-1, -1}, {1, 1}, {1, 2}},
       {{1, 1}, {-2, -2}, {-2, -2}},   {{1, 1}, {-2, -2}, {-1, -1}},   {{1, 1}, {-2, -2}, {1, 2}},
       {{1, 1}, {-1, -1}, {-2, -2}},   {{1, 1}, {-1, -1}, {-1, -1}},   {{1, 1}, {-1, -1}, {1, 2}},
       {{1, 1}, {1, 2}, {-2, -2}},     {{1, 1}, {1, 2}, {-1, -1}},     {{1, 1}, {1, 2}, {1, 3}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {4, 77, 3}, /*out_shape*/ {2, 2, 77, 3}, /*rank_mesh*/ {2, 2, 3},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{0, 1}}},
       {{1, pair{0, 0}}},
       {{2, pair{2, 3}}}},
      {{{-2, -2}, {-2, -2}, {-2, -2}}, {{-2, -2}, {-2, -2}, {-1, -1}}, {{-2, -2}, {-2, -2}, {2, 3}},
       {{-2, -2}, {-1, -1}, {-2, -2}}, {{-2, -2}, {-1, -1}, {-1, -1}}, {{-2, -2}, {-1, -1}, {2, 3}},
       {{-2, -2}, {0, 0}, {-2, -2}},   {{-2, -2}, {0, 0}, {-1, -1}},   {{-2, -2}, {0, 0}, {2, 3}},
       {{-1, -1}, {-2, -2}, {-2, -2}}, {{-1, -1}, {-2, -2}, {-1, -1}}, {{-1, -1}, {-2, -2}, {2, 3}},
       {{-1, -1}, {-1, -1}, {-2, -2}}, {{-1, -1}, {-1, -1}, {-1, -1}}, {{-1, -1}, {-1, -1}, {2, 3}},
       {{-1, -1}, {0, 0}, {-2, -2}},   {{-1, -1}, {0, 0}, {-1, -1}},   {{-1, -1}, {0, 0}, {2, 3}},
       {{0, 0}, {-2, -2}, {-2, -2}},   {{0, 0}, {-2, -2}, {-1, -1}},   {{0, 0}, {-2, -2}, {2, 3}},
       {{0, 0}, {-1, -1}, {-2, -2}},   {{0, 0}, {-1, -1}, {-1, -1}},   {{0, 0}, {-1, -1}, {2, 3}},
       {{0, 0}, {0, 1}, {-2, -2}},     {{0, 0}, {0, 1}, {-1, -1}},     {{0, 0}, {0, 1}, {2, 3}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {2, 3, 2, 5}, /*out_shape*/ {12, 5}, /*rank_mesh*/ {2, 3, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{1, 0}}},
       {{0, pair{0, 0}}, {1, pair{1, 0}}, {2, pair{2, 0}}},
       {{2, pair{0, 0}}}},
      {{{-2, -2}, {-2, -2}, {-2, -2}},
       {{-2, -2}, {-2, -2}, {-1, -1}},
       {{-2, -2}, {-2, -2}, {0, 0}},
       {{-2, -2}, {-1, -1}, {-2, -2}},
       {{-2, -2}, {-1, -1}, {-1, -1}},
       {{-2, -2}, {-1, -1}, {0, 0}},
       {{-1, -1}, {-2, -2}, {-2, -2}},
       {{-1, -1}, {-2, -2}, {-1, -1}},
       {{-1, -1}, {-2, -2}, {0, 0}},
       {{-1, -1}, {-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}, {-1, -1}},
       {{-1, -1}, {-1, -1}, {0, 0}},
       {{0, 0}, {-2, -2}, {-2, -2}},
       {{0, 0}, {-2, -2}, {-1, -1}},
       {{0, 0}, {-1, -1}, {-2, -2}},
       {{0, 0}, {-1, -1}, {-1, -1}},
       {{0, 0}, {1, 0}, {-2, -2}},
       {{0, 0}, {1, 0}, {-1, -1}},
       {{0, 0}, {1, 0}, {2, 0}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {2, 1, 3, 2, 5}, /*out_shape*/ {12, 1, 5}, /*rank_mesh*/ {2, 3, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{2, 0}}},
       {{0, pair{0, 0}}, {1, pair{2, 0}}, {2, pair{3, 0}}},
       {{2, pair{0, 0}}}},
      {{{-2, -2}, {-2, -2}, {-2, -2}},
       {{-2, -2}, {-2, -2}, {-1, -1}},
       {{-2, -2}, {-2, -2}, {0, 0}},
       {{-2, -2}, {-1, -1}, {-2, -2}},
       {{-2, -2}, {-1, -1}, {-1, -1}},
       {{-2, -2}, {-1, -1}, {0, 0}},
       {{-1, -1}, {-2, -2}, {-2, -2}},
       {{-1, -1}, {-2, -2}, {-1, -1}},
       {{-1, -1}, {-2, -2}, {0, 0}},
       {{-1, -1}, {-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}, {-1, -1}},
       {{-1, -1}, {-1, -1}, {0, 0}},
       {{0, 0}, {-2, -2}, {-2, -2}},
       {{0, 0}, {-2, -2}, {-1, -1}},
       {{0, 0}, {-1, -1}, {-2, -2}},
       {{0, 0}, {-1, -1}, {-1, -1}},
       {{0, 0}, {2, 0}, {-2, -2}},
       {{0, 0}, {2, 0}, {-1, -1}},
       {{0, 0}, {2, 0}, {3, 0}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {8, 4}, /*out_shape*/ {2, 2, 8}, /*rank_mesh*/ {2, 2, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{0, 1}}},
       {{0, pair{0, 0}}, {1, pair{0, 1}}, {2, pair{0, 2}}},
       {{0, pair{0, 0}}, {2, pair{0, 1}}},
       {{1, pair{0, 0}}},
       {{1, pair{0, 0}}, {2, pair{0, 1}}},
       {{2, pair{0, 0}}}},
      {{{-2, -2}, {-2, -2}, {-2, -2}}, {{-2, -2}, {-2, -2}, {-1, -1}}, {{-2, -2}, {-2, -2}, {0, 0}},
       {{-2, -2}, {-1, -1}, {-2, -2}}, {{-2, -2}, {-1, -1}, {-1, -1}}, {{-2, -2}, {-1, -1}, {0, 0}},
       {{-2, -2}, {0, 0}, {-2, -2}},   {{-2, -2}, {0, 0}, {-1, -1}},   {{-2, -2}, {0, 0}, {0, 1}},
       {{-1, -1}, {-2, -2}, {-2, -2}}, {{-1, -1}, {-2, -2}, {-1, -1}}, {{-1, -1}, {-2, -2}, {0, 0}},
       {{-1, -1}, {-1, -1}, {-2, -2}}, {{-1, -1}, {-1, -1}, {-1, -1}}, {{-1, -1}, {-1, -1}, {0, 0}},
       {{-1, -1}, {0, 0}, {-2, -2}},   {{-1, -1}, {0, 0}, {-1, -1}},   {{-1, -1}, {0, 0}, {0, 1}},
       {{0, 0}, {-2, -2}, {-2, -2}},   {{0, 0}, {-2, -2}, {-1, -1}},   {{0, 0}, {-2, -2}, {0, 1}},
       {{0, 0}, {-1, -1}, {-2, -2}},   {{0, 0}, {-1, -1}, {-1, -1}},   {{0, 0}, {-1, -1}, {0, 1}},
       {{0, 0}, {0, 1}, {-2, -2}},     {{0, 0}, {0, 1}, {-1, -1}},     {{0, 0}, {0, 1}, {0, 2}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {8, 2, 2}, /*out_shape*/ {2, 2, 4, 2}, /*rank_mesh*/ {2, 2, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{0, 1}}},
       {{0, pair{0, 0}}, {1, pair{0, 1}}, {2, pair{0, 2}}},
       {{0, pair{0, 0}}, {2, pair{0, 1}}},
       {{0, pair{2, 3}}},
       {{1, pair{0, 0}}},
       {{1, pair{0, 0}}, {2, pair{0, 1}}},
       {{1, pair{2, 3}}},
       {{2, pair{0, 0}}},
       {{2, pair{2, 3}}}},
      {{{-2, -2}, {-2, -2}, {-2, -2}}, {{-2, -2}, {-2, -2}, {-1, -1}},
       {{-2, -2}, {-2, -2}, {0, 0}},   {{-2, -2}, {-2, -2}, {2, 3}},
       {{-2, -2}, {-1, -1}, {-2, -2}}, {{-2, -2}, {-1, -1}, {-1, -1}},
       {{-2, -2}, {-1, -1}, {0, 0}},   {{-2, -2}, {-1, -1}, {2, 3}},
       {{-2, -2}, {0, 0}, {-2, -2}},   {{-2, -2}, {0, 0}, {-1, -1}},
       {{-2, -2}, {0, 0}, {0, 1}},     {{-2, -2}, {0, 0}, {2, 3}},
       {{-2, -2}, {2, 3}, {-2, -2}},   {{-2, -2}, {2, 3}, {-1, -1}},
       {{-2, -2}, {2, 3}, {0, 0}},     {{-1, -1}, {-2, -2}, {-2, -2}},
       {{-1, -1}, {-2, -2}, {-1, -1}}, {{-1, -1}, {-2, -2}, {0, 0}},
       {{-1, -1}, {-2, -2}, {2, 3}},   {{-1, -1}, {-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}, {-1, -1}}, {{-1, -1}, {-1, -1}, {0, 0}},
       {{-1, -1}, {-1, -1}, {2, 3}},   {{-1, -1}, {0, 0}, {-2, -2}},
       {{-1, -1}, {0, 0}, {-1, -1}},   {{-1, -1}, {0, 0}, {0, 1}},
       {{-1, -1}, {0, 0}, {2, 3}},     {{-1, -1}, {2, 3}, {-2, -2}},
       {{-1, -1}, {2, 3}, {-1, -1}},   {{-1, -1}, {2, 3}, {0, 0}},
       {{0, 0}, {-2, -2}, {-2, -2}},   {{0, 0}, {-2, -2}, {-1, -1}},
       {{0, 0}, {-2, -2}, {0, 1}},     {{0, 0}, {-2, -2}, {2, 3}},
       {{0, 0}, {-1, -1}, {-2, -2}},   {{0, 0}, {-1, -1}, {-1, -1}},
       {{0, 0}, {-1, -1}, {0, 1}},     {{0, 0}, {-1, -1}, {2, 3}},
       {{0, 0}, {0, 1}, {-2, -2}},     {{0, 0}, {0, 1}, {-1, -1}},
       {{0, 0}, {0, 1}, {0, 2}},       {{0, 0}, {0, 1}, {2, 3}},
       {{0, 0}, {2, 3}, {-2, -2}},     {{0, 0}, {2, 3}, {-1, -1}},
       {{0, 0}, {2, 3}, {0, 1}},       {{2, 3}, {-2, -2}, {-2, -2}},
       {{2, 3}, {-2, -2}, {-1, -1}},   {{2, 3}, {-2, -2}, {0, 0}},
       {{2, 3}, {-1, -1}, {-2, -2}},   {{2, 3}, {-1, -1}, {-1, -1}},
       {{2, 3}, {-1, -1}, {0, 0}},     {{2, 3}, {0, 0}, {-2, -2}},
       {{2, 3}, {0, 0}, {-1, -1}},     {{2, 3}, {0, 0}, {0, 1}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {8, 2, 1, 2}, /*out_shape*/ {2, 2, 1, 4, 2}, /*rank_mesh*/ {2, 2, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{0, 1}}},
       {{0, pair{0, 0}}, {1, pair{0, 1}}, {2, pair{0, 3}}},
       {{0, pair{0, 0}}, {2, pair{0, 1}}},
       {{0, pair{3, 4}}},
       {{1, pair{0, 0}}},
       {{1, pair{0, 0}}, {2, pair{0, 1}}},
       {{1, pair{3, 4}}},
       {{2, pair{0, 0}}},
       {{2, pair{3, 4}}}},
      {{{-2, -2}, {-2, -2}, {-2, -2}}, {{-2, -2}, {-2, -2}, {-1, -1}},
       {{-2, -2}, {-2, -2}, {0, 0}},   {{-2, -2}, {-2, -2}, {3, 4}},
       {{-2, -2}, {-1, -1}, {-2, -2}}, {{-2, -2}, {-1, -1}, {-1, -1}},
       {{-2, -2}, {-1, -1}, {0, 0}},   {{-2, -2}, {-1, -1}, {3, 4}},
       {{-2, -2}, {0, 0}, {-2, -2}},   {{-2, -2}, {0, 0}, {-1, -1}},
       {{-2, -2}, {0, 0}, {0, 1}},     {{-2, -2}, {0, 0}, {3, 4}},
       {{-2, -2}, {3, 4}, {-2, -2}},   {{-2, -2}, {3, 4}, {-1, -1}},
       {{-2, -2}, {3, 4}, {0, 0}},     {{-1, -1}, {-2, -2}, {-2, -2}},
       {{-1, -1}, {-2, -2}, {-1, -1}}, {{-1, -1}, {-2, -2}, {0, 0}},
       {{-1, -1}, {-2, -2}, {3, 4}},   {{-1, -1}, {-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}, {-1, -1}}, {{-1, -1}, {-1, -1}, {0, 0}},
       {{-1, -1}, {-1, -1}, {3, 4}},   {{-1, -1}, {0, 0}, {-2, -2}},
       {{-1, -1}, {0, 0}, {-1, -1}},   {{-1, -1}, {0, 0}, {0, 1}},
       {{-1, -1}, {0, 0}, {3, 4}},     {{-1, -1}, {3, 4}, {-2, -2}},
       {{-1, -1}, {3, 4}, {-1, -1}},   {{-1, -1}, {3, 4}, {0, 0}},
       {{0, 0}, {-2, -2}, {-2, -2}},   {{0, 0}, {-2, -2}, {-1, -1}},
       {{0, 0}, {-2, -2}, {0, 1}},     {{0, 0}, {-2, -2}, {3, 4}},
       {{0, 0}, {-1, -1}, {-2, -2}},   {{0, 0}, {-1, -1}, {-1, -1}},
       {{0, 0}, {-1, -1}, {0, 1}},     {{0, 0}, {-1, -1}, {3, 4}},
       {{0, 0}, {0, 1}, {-2, -2}},     {{0, 0}, {0, 1}, {-1, -1}},
       {{0, 0}, {0, 1}, {0, 3}},       {{0, 0}, {0, 1}, {3, 4}},
       {{0, 0}, {3, 4}, {-2, -2}},     {{0, 0}, {3, 4}, {-1, -1}},
       {{0, 0}, {3, 4}, {0, 1}},       {{3, 4}, {-2, -2}, {-2, -2}},
       {{3, 4}, {-2, -2}, {-1, -1}},   {{3, 4}, {-2, -2}, {0, 0}},
       {{3, 4}, {-1, -1}, {-2, -2}},   {{3, 4}, {-1, -1}, {-1, -1}},
       {{3, 4}, {-1, -1}, {0, 0}},     {{3, 4}, {0, 0}, {-2, -2}},
       {{3, 4}, {0, 0}, {-1, -1}},     {{3, 4}, {0, 0}, {0, 1}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {6, 4}, /*out_shape*/ {2, 3, 2, 2}, /*rank_mesh*/ {2, 3, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{0, 1}}},
       {{0, pair{1, 2}}},
       {{0, pair{1, 2}}, {2, pair{1, 3}}},
       {{2, pair{0, 0}}},
       {{2, pair{1, 2}}}},
      {{{-2, -2}, {-2, -2}, {-2, -2}}, {{-2, -2}, {-2, -2}, {-1, -1}},
       {{-2, -2}, {-2, -2}, {0, 0}},   {{-2, -2}, {-2, -2}, {1, 2}},
       {{-2, -2}, {-1, -1}, {-2, -2}}, {{-2, -2}, {-1, -1}, {-1, -1}},
       {{-2, -2}, {-1, -1}, {0, 0}},   {{-2, -2}, {-1, -1}, {1, 2}},
       {{-1, -1}, {-2, -2}, {-2, -2}}, {{-1, -1}, {-2, -2}, {-1, -1}},
       {{-1, -1}, {-2, -2}, {0, 0}},   {{-1, -1}, {-2, -2}, {1, 2}},
       {{-1, -1}, {-1, -1}, {-2, -2}}, {{-1, -1}, {-1, -1}, {-1, -1}},
       {{-1, -1}, {-1, -1}, {0, 0}},   {{-1, -1}, {-1, -1}, {1, 2}},
       {{0, 0}, {-2, -2}, {-2, -2}},   {{0, 0}, {-2, -2}, {-1, -1}},
       {{0, 0}, {-2, -2}, {1, 2}},     {{0, 0}, {-1, -1}, {-2, -2}},
       {{0, 0}, {-1, -1}, {-1, -1}},   {{0, 0}, {-1, -1}, {1, 2}},
       {{0, 0}, {0, 1}, {-2, -2}},     {{0, 0}, {0, 1}, {-1, -1}},
       {{0, 0}, {0, 1}, {1, 2}},       {{1, 2}, {-2, -2}, {-2, -2}},
       {{1, 2}, {-2, -2}, {-1, -1}},   {{1, 2}, {-2, -2}, {0, 0}},
       {{1, 2}, {-2, -2}, {1, 3}},     {{1, 2}, {-1, -1}, {-2, -2}},
       {{1, 2}, {-1, -1}, {-1, -1}},   {{1, 2}, {-1, -1}, {0, 0}},
       {{1, 2}, {-1, -1}, {1, 3}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {6, 4, 1}, /*out_shape*/ {2, 1, 3, 2, 2}, /*rank_mesh*/ {2, 3, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{0, 2}}},
       {{0, pair{1, 3}}},
       {{0, pair{1, 3}}, {2, pair{1, 4}}},
       {{2, pair{0, 0}}},
       {{2, pair{1, 3}}}},
      {{{-2, -2}, {-2, -2}, {-2, -2}}, {{-2, -2}, {-2, -2}, {-1, -1}},
       {{-2, -2}, {-2, -2}, {0, 0}},   {{-2, -2}, {-2, -2}, {1, 3}},
       {{-2, -2}, {-1, -1}, {-2, -2}}, {{-2, -2}, {-1, -1}, {-1, -1}},
       {{-2, -2}, {-1, -1}, {0, 0}},   {{-2, -2}, {-1, -1}, {1, 3}},
       {{-1, -1}, {-2, -2}, {-2, -2}}, {{-1, -1}, {-2, -2}, {-1, -1}},
       {{-1, -1}, {-2, -2}, {0, 0}},   {{-1, -1}, {-2, -2}, {1, 3}},
       {{-1, -1}, {-1, -1}, {-2, -2}}, {{-1, -1}, {-1, -1}, {-1, -1}},
       {{-1, -1}, {-1, -1}, {0, 0}},   {{-1, -1}, {-1, -1}, {1, 3}},
       {{0, 0}, {-2, -2}, {-2, -2}},   {{0, 0}, {-2, -2}, {-1, -1}},
       {{0, 0}, {-2, -2}, {1, 3}},     {{0, 0}, {-1, -1}, {-2, -2}},
       {{0, 0}, {-1, -1}, {-1, -1}},   {{0, 0}, {-1, -1}, {1, 3}},
       {{0, 0}, {0, 2}, {-2, -2}},     {{0, 0}, {0, 2}, {-1, -1}},
       {{0, 0}, {0, 2}, {1, 3}},       {{1, 3}, {-2, -2}, {-2, -2}},
       {{1, 3}, {-2, -2}, {-1, -1}},   {{1, 3}, {-2, -2}, {0, 0}},
       {{1, 3}, {-2, -2}, {1, 4}},     {{1, 3}, {-1, -1}, {-2, -2}},
       {{1, 3}, {-1, -1}, {-1, -1}},   {{1, 3}, {-1, -1}, {0, 0}},
       {{1, 3}, {-1, -1}, {1, 4}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {6, 3, 4}, /*out_shape*/ {2, 3, 3, 2, 2}, /*rank_mesh*/ {2, 3, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{0, 1}}},
       {{0, pair{2, 3}}},
       {{0, pair{2, 3}}, {2, pair{2, 4}}},
       {{1, pair{1, 2}}},
       {{2, pair{0, 0}}},
       {{2, pair{2, 3}}}},
      {{{-2, -2}, {-2, -2}, {-2, -2}}, {{-2, -2}, {-2, -2}, {-1, -1}},
       {{-2, -2}, {-2, -2}, {0, 0}},   {{-2, -2}, {-2, -2}, {2, 3}},
       {{-2, -2}, {-1, -1}, {-2, -2}}, {{-2, -2}, {-1, -1}, {-1, -1}},
       {{-2, -2}, {-1, -1}, {0, 0}},   {{-2, -2}, {-1, -1}, {2, 3}},
       {{-2, -2}, {1, 2}, {-2, -2}},   {{-2, -2}, {1, 2}, {-1, -1}},
       {{-2, -2}, {1, 2}, {0, 0}},     {{-2, -2}, {1, 2}, {2, 3}},
       {{-1, -1}, {-2, -2}, {-2, -2}}, {{-1, -1}, {-2, -2}, {-1, -1}},
       {{-1, -1}, {-2, -2}, {0, 0}},   {{-1, -1}, {-2, -2}, {2, 3}},
       {{-1, -1}, {-1, -1}, {-2, -2}}, {{-1, -1}, {-1, -1}, {-1, -1}},
       {{-1, -1}, {-1, -1}, {0, 0}},   {{-1, -1}, {-1, -1}, {2, 3}},
       {{-1, -1}, {1, 2}, {-2, -2}},   {{-1, -1}, {1, 2}, {-1, -1}},
       {{-1, -1}, {1, 2}, {0, 0}},     {{-1, -1}, {1, 2}, {2, 3}},
       {{0, 0}, {-2, -2}, {-2, -2}},   {{0, 0}, {-2, -2}, {-1, -1}},
       {{0, 0}, {-2, -2}, {2, 3}},     {{0, 0}, {-1, -1}, {-2, -2}},
       {{0, 0}, {-1, -1}, {-1, -1}},   {{0, 0}, {-1, -1}, {2, 3}},
       {{0, 0}, {0, 1}, {-2, -2}},     {{0, 0}, {0, 1}, {-1, -1}},
       {{0, 0}, {0, 1}, {2, 3}},       {{0, 0}, {1, 2}, {-2, -2}},
       {{0, 0}, {1, 2}, {-1, -1}},     {{0, 0}, {1, 2}, {2, 3}},
       {{2, 3}, {-2, -2}, {-2, -2}},   {{2, 3}, {-2, -2}, {-1, -1}},
       {{2, 3}, {-2, -2}, {0, 0}},     {{2, 3}, {-2, -2}, {2, 4}},
       {{2, 3}, {-1, -1}, {-2, -2}},   {{2, 3}, {-1, -1}, {-1, -1}},
       {{2, 3}, {-1, -1}, {0, 0}},     {{2, 3}, {-1, -1}, {2, 4}},
       {{2, 3}, {1, 2}, {-2, -2}},     {{2, 3}, {1, 2}, {-1, -1}},
       {{2, 3}, {1, 2}, {0, 0}},       {{2, 3}, {1, 2}, {2, 4}}});
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {2, 8}, /*out_shape*/ {2, 2, 2, 2}, /*rank_mesh*/ {2, 2, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{1, 1}}},
       {{0, pair{1, 1}}, {1, pair{1, 2}}},
       {{0, pair{1, 1}}, {1, pair{1, 2}}, {2, pair{1, 3}}},
       {{0, pair{1, 1}}, {2, pair{1, 2}}},
       {{1, pair{0, 0}}},
       {{1, pair{1, 1}}},
       {{1, pair{1, 1}}, {2, pair{1, 2}}},
       {{2, pair{0, 0}}},
       {{2, pair{1, 1}}}},
      {{{-2, -2}, {-2, -2}, {-2, -2}}, {{-2, -2}, {-2, -2}, {-1, -1}},
       {{-2, -2}, {-2, -2}, {0, 0}},   {{-2, -2}, {-2, -2}, {1, 1}},
       {{-2, -2}, {-1, -1}, {-2, -2}}, {{-2, -2}, {-1, -1}, {-1, -1}},
       {{-2, -2}, {-1, -1}, {0, 0}},   {{-2, -2}, {-1, -1}, {1, 1}},
       {{-2, -2}, {0, 0}, {-2, -2}},   {{-2, -2}, {0, 0}, {-1, -1}},
       {{-2, -2}, {0, 0}, {1, 1}},     {{-2, -2}, {1, 1}, {-2, -2}},
       {{-2, -2}, {1, 1}, {-1, -1}},   {{-2, -2}, {1, 1}, {0, 0}},
       {{-2, -2}, {1, 1}, {1, 2}},     {{-1, -1}, {-2, -2}, {-2, -2}},
       {{-1, -1}, {-2, -2}, {-1, -1}}, {{-1, -1}, {-2, -2}, {0, 0}},
       {{-1, -1}, {-2, -2}, {1, 1}},   {{-1, -1}, {-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}, {-1, -1}}, {{-1, -1}, {-1, -1}, {0, 0}},
       {{-1, -1}, {-1, -1}, {1, 1}},   {{-1, -1}, {0, 0}, {-2, -2}},
       {{-1, -1}, {0, 0}, {-1, -1}},   {{-1, -1}, {0, 0}, {1, 1}},
       {{-1, -1}, {1, 1}, {-2, -2}},   {{-1, -1}, {1, 1}, {-1, -1}},
       {{-1, -1}, {1, 1}, {0, 0}},     {{-1, -1}, {1, 1}, {1, 2}},
       {{0, 0}, {-2, -2}, {-2, -2}},   {{0, 0}, {-2, -2}, {-1, -1}},
       {{0, 0}, {-2, -2}, {1, 1}},     {{0, 0}, {-1, -1}, {-2, -2}},
       {{0, 0}, {-1, -1}, {-1, -1}},   {{0, 0}, {-1, -1}, {1, 1}},
       {{0, 0}, {1, 1}, {-2, -2}},     {{0, 0}, {1, 1}, {-1, -1}},
       {{0, 0}, {1, 1}, {1, 2}},       {{1, 1}, {-2, -2}, {-2, -2}},
       {{1, 1}, {-2, -2}, {-1, -1}},   {{1, 1}, {-2, -2}, {0, 0}},
       {{1, 1}, {-2, -2}, {1, 2}},     {{1, 1}, {-1, -1}, {-2, -2}},
       {{1, 1}, {-1, -1}, {-1, -1}},   {{1, 1}, {-1, -1}, {0, 0}},
       {{1, 1}, {-1, -1}, {1, 2}},     {{1, 1}, {0, 0}, {-2, -2}},
       {{1, 1}, {0, 0}, {-1, -1}},     {{1, 1}, {0, 0}, {1, 2}},
       {{1, 1}, {1, 2}, {-2, -2}},     {{1, 1}, {1, 2}, {-1, -1}},
       {{1, 1}, {1, 2}, {0, 0}},       {{1, 1}, {1, 2}, {1, 3}}});
  // 4D-split
  TestEnumerateNdSbpIn2OutSignatures(
      /*in_shape*/ {4, 77, 8}, /*out_shape*/ {2, 2, 77, 2, 4}, /*rank_mesh*/ {2, 2, 2, 2},
      {{{0, pair{0, 0}}},
       {{0, pair{0, 0}}, {1, pair{0, 1}}},
       {{0, pair{0, 0}}, {2, pair{0, 1}}},
       {{0, pair{0, 0}}, {3, pair{0, 1}}},
       {{0, pair{2, 3}}},
       {{0, pair{2, 3}}, {1, pair{2, 4}}},
       {{0, pair{2, 3}}, {1, pair{2, 4}}, {2, pair{2, 4}}},
       {{0, pair{2, 3}}, {1, pair{2, 4}}, {3, pair{2, 4}}},
       {{0, pair{2, 3}}, {2, pair{2, 4}}},
       {{0, pair{2, 3}}, {2, pair{2, 4}}, {3, pair{2, 4}}},
       {{0, pair{2, 3}}, {3, pair{2, 4}}},
       {{1, pair{0, 0}}},
       {{1, pair{0, 0}}, {2, pair{0, 1}}},
       {{1, pair{0, 0}}, {3, pair{0, 1}}},
       {{1, pair{2, 3}}},
       {{1, pair{2, 3}}, {2, pair{2, 4}}},
       {{1, pair{2, 3}}, {2, pair{2, 4}}, {3, pair{2, 4}}},
       {{1, pair{2, 3}}, {3, pair{2, 4}}},
       {{2, pair{0, 0}}},
       {{2, pair{0, 0}}, {3, pair{0, 1}}},
       {{2, pair{2, 3}}},
       {{2, pair{2, 3}}, {3, pair{2, 4}}},
       {{3, pair{0, 0}}},
       {{3, pair{2, 3}}}},
      {{{-2, -2}, {-2, -2}, {-2, -2}, {-2, -2}}, {{-2, -2}, {-2, -2}, {-2, -2}, {-1, -1}},
       {{-2, -2}, {-2, -2}, {-2, -2}, {0, 0}},   {{-2, -2}, {-2, -2}, {-2, -2}, {2, 3}},
       {{-2, -2}, {-2, -2}, {-1, -1}, {-2, -2}}, {{-2, -2}, {-2, -2}, {-1, -1}, {-1, -1}},
       {{-2, -2}, {-2, -2}, {-1, -1}, {0, 0}},   {{-2, -2}, {-2, -2}, {-1, -1}, {2, 3}},
       {{-2, -2}, {-2, -2}, {0, 0}, {-2, -2}},   {{-2, -2}, {-2, -2}, {0, 0}, {-1, -1}},
       {{-2, -2}, {-2, -2}, {0, 0}, {0, 1}},     {{-2, -2}, {-2, -2}, {0, 0}, {2, 3}},
       {{-2, -2}, {-2, -2}, {2, 3}, {-2, -2}},   {{-2, -2}, {-2, -2}, {2, 3}, {-1, -1}},
       {{-2, -2}, {-2, -2}, {2, 3}, {0, 0}},     {{-2, -2}, {-2, -2}, {2, 3}, {2, 4}},
       {{-2, -2}, {-1, -1}, {-2, -2}, {-2, -2}}, {{-2, -2}, {-1, -1}, {-2, -2}, {-1, -1}},
       {{-2, -2}, {-1, -1}, {-2, -2}, {0, 0}},   {{-2, -2}, {-1, -1}, {-2, -2}, {2, 3}},
       {{-2, -2}, {-1, -1}, {-1, -1}, {-2, -2}}, {{-2, -2}, {-1, -1}, {-1, -1}, {-1, -1}},
       {{-2, -2}, {-1, -1}, {-1, -1}, {0, 0}},   {{-2, -2}, {-1, -1}, {-1, -1}, {2, 3}},
       {{-2, -2}, {-1, -1}, {0, 0}, {-2, -2}},   {{-2, -2}, {-1, -1}, {0, 0}, {-1, -1}},
       {{-2, -2}, {-1, -1}, {0, 0}, {0, 1}},     {{-2, -2}, {-1, -1}, {0, 0}, {2, 3}},
       {{-2, -2}, {-1, -1}, {2, 3}, {-2, -2}},   {{-2, -2}, {-1, -1}, {2, 3}, {-1, -1}},
       {{-2, -2}, {-1, -1}, {2, 3}, {0, 0}},     {{-2, -2}, {-1, -1}, {2, 3}, {2, 4}},
       {{-2, -2}, {0, 0}, {-2, -2}, {-2, -2}},   {{-2, -2}, {0, 0}, {-2, -2}, {-1, -1}},
       {{-2, -2}, {0, 0}, {-2, -2}, {0, 1}},     {{-2, -2}, {0, 0}, {-2, -2}, {2, 3}},
       {{-2, -2}, {0, 0}, {-1, -1}, {-2, -2}},   {{-2, -2}, {0, 0}, {-1, -1}, {-1, -1}},
       {{-2, -2}, {0, 0}, {-1, -1}, {0, 1}},     {{-2, -2}, {0, 0}, {-1, -1}, {2, 3}},
       {{-2, -2}, {0, 0}, {0, 1}, {-2, -2}},     {{-2, -2}, {0, 0}, {0, 1}, {-1, -1}},
       {{-2, -2}, {0, 0}, {0, 1}, {2, 3}},       {{-2, -2}, {0, 0}, {2, 3}, {-2, -2}},
       {{-2, -2}, {0, 0}, {2, 3}, {-1, -1}},     {{-2, -2}, {0, 0}, {2, 3}, {0, 1}},
       {{-2, -2}, {0, 0}, {2, 3}, {2, 4}},       {{-2, -2}, {2, 3}, {-2, -2}, {-2, -2}},
       {{-2, -2}, {2, 3}, {-2, -2}, {-1, -1}},   {{-2, -2}, {2, 3}, {-2, -2}, {0, 0}},
       {{-2, -2}, {2, 3}, {-2, -2}, {2, 4}},     {{-2, -2}, {2, 3}, {-1, -1}, {-2, -2}},
       {{-2, -2}, {2, 3}, {-1, -1}, {-1, -1}},   {{-2, -2}, {2, 3}, {-1, -1}, {0, 0}},
       {{-2, -2}, {2, 3}, {-1, -1}, {2, 4}},     {{-2, -2}, {2, 3}, {0, 0}, {-2, -2}},
       {{-2, -2}, {2, 3}, {0, 0}, {-1, -1}},     {{-2, -2}, {2, 3}, {0, 0}, {0, 1}},
       {{-2, -2}, {2, 3}, {0, 0}, {2, 4}},       {{-2, -2}, {2, 3}, {2, 4}, {-2, -2}},
       {{-2, -2}, {2, 3}, {2, 4}, {-1, -1}},     {{-2, -2}, {2, 3}, {2, 4}, {0, 0}},
       {{-2, -2}, {2, 3}, {2, 4}, {2, 4}},       {{-1, -1}, {-2, -2}, {-2, -2}, {-2, -2}},
       {{-1, -1}, {-2, -2}, {-2, -2}, {-1, -1}}, {{-1, -1}, {-2, -2}, {-2, -2}, {0, 0}},
       {{-1, -1}, {-2, -2}, {-2, -2}, {2, 3}},   {{-1, -1}, {-2, -2}, {-1, -1}, {-2, -2}},
       {{-1, -1}, {-2, -2}, {-1, -1}, {-1, -1}}, {{-1, -1}, {-2, -2}, {-1, -1}, {0, 0}},
       {{-1, -1}, {-2, -2}, {-1, -1}, {2, 3}},   {{-1, -1}, {-2, -2}, {0, 0}, {-2, -2}},
       {{-1, -1}, {-2, -2}, {0, 0}, {-1, -1}},   {{-1, -1}, {-2, -2}, {0, 0}, {0, 1}},
       {{-1, -1}, {-2, -2}, {0, 0}, {2, 3}},     {{-1, -1}, {-2, -2}, {2, 3}, {-2, -2}},
       {{-1, -1}, {-2, -2}, {2, 3}, {-1, -1}},   {{-1, -1}, {-2, -2}, {2, 3}, {0, 0}},
       {{-1, -1}, {-2, -2}, {2, 3}, {2, 4}},     {{-1, -1}, {-1, -1}, {-2, -2}, {-2, -2}},
       {{-1, -1}, {-1, -1}, {-2, -2}, {-1, -1}}, {{-1, -1}, {-1, -1}, {-2, -2}, {0, 0}},
       {{-1, -1}, {-1, -1}, {-2, -2}, {2, 3}},   {{-1, -1}, {-1, -1}, {-1, -1}, {-2, -2}},
       {{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}}, {{-1, -1}, {-1, -1}, {-1, -1}, {0, 0}},
       {{-1, -1}, {-1, -1}, {-1, -1}, {2, 3}},   {{-1, -1}, {-1, -1}, {0, 0}, {-2, -2}},
       {{-1, -1}, {-1, -1}, {0, 0}, {-1, -1}},   {{-1, -1}, {-1, -1}, {0, 0}, {0, 1}},
       {{-1, -1}, {-1, -1}, {0, 0}, {2, 3}},     {{-1, -1}, {-1, -1}, {2, 3}, {-2, -2}},
       {{-1, -1}, {-1, -1}, {2, 3}, {-1, -1}},   {{-1, -1}, {-1, -1}, {2, 3}, {0, 0}},
       {{-1, -1}, {-1, -1}, {2, 3}, {2, 4}},     {{-1, -1}, {0, 0}, {-2, -2}, {-2, -2}},
       {{-1, -1}, {0, 0}, {-2, -2}, {-1, -1}},   {{-1, -1}, {0, 0}, {-2, -2}, {0, 1}},
       {{-1, -1}, {0, 0}, {-2, -2}, {2, 3}},     {{-1, -1}, {0, 0}, {-1, -1}, {-2, -2}},
       {{-1, -1}, {0, 0}, {-1, -1}, {-1, -1}},   {{-1, -1}, {0, 0}, {-1, -1}, {0, 1}},
       {{-1, -1}, {0, 0}, {-1, -1}, {2, 3}},     {{-1, -1}, {0, 0}, {0, 1}, {-2, -2}},
       {{-1, -1}, {0, 0}, {0, 1}, {-1, -1}},     {{-1, -1}, {0, 0}, {0, 1}, {2, 3}},
       {{-1, -1}, {0, 0}, {2, 3}, {-2, -2}},     {{-1, -1}, {0, 0}, {2, 3}, {-1, -1}},
       {{-1, -1}, {0, 0}, {2, 3}, {0, 1}},       {{-1, -1}, {0, 0}, {2, 3}, {2, 4}},
       {{-1, -1}, {2, 3}, {-2, -2}, {-2, -2}},   {{-1, -1}, {2, 3}, {-2, -2}, {-1, -1}},
       {{-1, -1}, {2, 3}, {-2, -2}, {0, 0}},     {{-1, -1}, {2, 3}, {-2, -2}, {2, 4}},
       {{-1, -1}, {2, 3}, {-1, -1}, {-2, -2}},   {{-1, -1}, {2, 3}, {-1, -1}, {-1, -1}},
       {{-1, -1}, {2, 3}, {-1, -1}, {0, 0}},     {{-1, -1}, {2, 3}, {-1, -1}, {2, 4}},
       {{-1, -1}, {2, 3}, {0, 0}, {-2, -2}},     {{-1, -1}, {2, 3}, {0, 0}, {-1, -1}},
       {{-1, -1}, {2, 3}, {0, 0}, {0, 1}},       {{-1, -1}, {2, 3}, {0, 0}, {2, 4}},
       {{-1, -1}, {2, 3}, {2, 4}, {-2, -2}},     {{-1, -1}, {2, 3}, {2, 4}, {-1, -1}},
       {{-1, -1}, {2, 3}, {2, 4}, {0, 0}},       {{-1, -1}, {2, 3}, {2, 4}, {2, 4}},
       {{0, 0}, {-2, -2}, {-2, -2}, {-2, -2}},   {{0, 0}, {-2, -2}, {-2, -2}, {-1, -1}},
       {{0, 0}, {-2, -2}, {-2, -2}, {0, 1}},     {{0, 0}, {-2, -2}, {-2, -2}, {2, 3}},
       {{0, 0}, {-2, -2}, {-1, -1}, {-2, -2}},   {{0, 0}, {-2, -2}, {-1, -1}, {-1, -1}},
       {{0, 0}, {-2, -2}, {-1, -1}, {0, 1}},     {{0, 0}, {-2, -2}, {-1, -1}, {2, 3}},
       {{0, 0}, {-2, -2}, {0, 1}, {-2, -2}},     {{0, 0}, {-2, -2}, {0, 1}, {-1, -1}},
       {{0, 0}, {-2, -2}, {0, 1}, {2, 3}},       {{0, 0}, {-2, -2}, {2, 3}, {-2, -2}},
       {{0, 0}, {-2, -2}, {2, 3}, {-1, -1}},     {{0, 0}, {-2, -2}, {2, 3}, {0, 1}},
       {{0, 0}, {-2, -2}, {2, 3}, {2, 4}},       {{0, 0}, {-1, -1}, {-2, -2}, {-2, -2}},
       {{0, 0}, {-1, -1}, {-2, -2}, {-1, -1}},   {{0, 0}, {-1, -1}, {-2, -2}, {0, 1}},
       {{0, 0}, {-1, -1}, {-2, -2}, {2, 3}},     {{0, 0}, {-1, -1}, {-1, -1}, {-2, -2}},
       {{0, 0}, {-1, -1}, {-1, -1}, {-1, -1}},   {{0, 0}, {-1, -1}, {-1, -1}, {0, 1}},
       {{0, 0}, {-1, -1}, {-1, -1}, {2, 3}},     {{0, 0}, {-1, -1}, {0, 1}, {-2, -2}},
       {{0, 0}, {-1, -1}, {0, 1}, {-1, -1}},     {{0, 0}, {-1, -1}, {0, 1}, {2, 3}},
       {{0, 0}, {-1, -1}, {2, 3}, {-2, -2}},     {{0, 0}, {-1, -1}, {2, 3}, {-1, -1}},
       {{0, 0}, {-1, -1}, {2, 3}, {0, 1}},       {{0, 0}, {-1, -1}, {2, 3}, {2, 4}},
       {{0, 0}, {0, 1}, {-2, -2}, {-2, -2}},     {{0, 0}, {0, 1}, {-2, -2}, {-1, -1}},
       {{0, 0}, {0, 1}, {-2, -2}, {2, 3}},       {{0, 0}, {0, 1}, {-1, -1}, {-2, -2}},
       {{0, 0}, {0, 1}, {-1, -1}, {-1, -1}},     {{0, 0}, {0, 1}, {-1, -1}, {2, 3}},
       {{0, 0}, {0, 1}, {2, 3}, {-2, -2}},       {{0, 0}, {0, 1}, {2, 3}, {-1, -1}},
       {{0, 0}, {0, 1}, {2, 3}, {2, 4}},         {{0, 0}, {2, 3}, {-2, -2}, {-2, -2}},
       {{0, 0}, {2, 3}, {-2, -2}, {-1, -1}},     {{0, 0}, {2, 3}, {-2, -2}, {0, 1}},
       {{0, 0}, {2, 3}, {-2, -2}, {2, 4}},       {{0, 0}, {2, 3}, {-1, -1}, {-2, -2}},
       {{0, 0}, {2, 3}, {-1, -1}, {-1, -1}},     {{0, 0}, {2, 3}, {-1, -1}, {0, 1}},
       {{0, 0}, {2, 3}, {-1, -1}, {2, 4}},       {{0, 0}, {2, 3}, {0, 1}, {-2, -2}},
       {{0, 0}, {2, 3}, {0, 1}, {-1, -1}},       {{0, 0}, {2, 3}, {0, 1}, {2, 4}},
       {{0, 0}, {2, 3}, {2, 4}, {-2, -2}},       {{0, 0}, {2, 3}, {2, 4}, {-1, -1}},
       {{0, 0}, {2, 3}, {2, 4}, {0, 1}},         {{0, 0}, {2, 3}, {2, 4}, {2, 4}},
       {{2, 3}, {-2, -2}, {-2, -2}, {-2, -2}},   {{2, 3}, {-2, -2}, {-2, -2}, {-1, -1}},
       {{2, 3}, {-2, -2}, {-2, -2}, {0, 0}},     {{2, 3}, {-2, -2}, {-2, -2}, {2, 4}},
       {{2, 3}, {-2, -2}, {-1, -1}, {-2, -2}},   {{2, 3}, {-2, -2}, {-1, -1}, {-1, -1}},
       {{2, 3}, {-2, -2}, {-1, -1}, {0, 0}},     {{2, 3}, {-2, -2}, {-1, -1}, {2, 4}},
       {{2, 3}, {-2, -2}, {0, 0}, {-2, -2}},     {{2, 3}, {-2, -2}, {0, 0}, {-1, -1}},
       {{2, 3}, {-2, -2}, {0, 0}, {0, 1}},       {{2, 3}, {-2, -2}, {0, 0}, {2, 4}},
       {{2, 3}, {-2, -2}, {2, 4}, {-2, -2}},     {{2, 3}, {-2, -2}, {2, 4}, {-1, -1}},
       {{2, 3}, {-2, -2}, {2, 4}, {0, 0}},       {{2, 3}, {-2, -2}, {2, 4}, {2, 4}},
       {{2, 3}, {-1, -1}, {-2, -2}, {-2, -2}},   {{2, 3}, {-1, -1}, {-2, -2}, {-1, -1}},
       {{2, 3}, {-1, -1}, {-2, -2}, {0, 0}},     {{2, 3}, {-1, -1}, {-2, -2}, {2, 4}},
       {{2, 3}, {-1, -1}, {-1, -1}, {-2, -2}},   {{2, 3}, {-1, -1}, {-1, -1}, {-1, -1}},
       {{2, 3}, {-1, -1}, {-1, -1}, {0, 0}},     {{2, 3}, {-1, -1}, {-1, -1}, {2, 4}},
       {{2, 3}, {-1, -1}, {0, 0}, {-2, -2}},     {{2, 3}, {-1, -1}, {0, 0}, {-1, -1}},
       {{2, 3}, {-1, -1}, {0, 0}, {0, 1}},       {{2, 3}, {-1, -1}, {0, 0}, {2, 4}},
       {{2, 3}, {-1, -1}, {2, 4}, {-2, -2}},     {{2, 3}, {-1, -1}, {2, 4}, {-1, -1}},
       {{2, 3}, {-1, -1}, {2, 4}, {0, 0}},       {{2, 3}, {-1, -1}, {2, 4}, {2, 4}},
       {{2, 3}, {0, 0}, {-2, -2}, {-2, -2}},     {{2, 3}, {0, 0}, {-2, -2}, {-1, -1}},
       {{2, 3}, {0, 0}, {-2, -2}, {0, 1}},       {{2, 3}, {0, 0}, {-2, -2}, {2, 4}},
       {{2, 3}, {0, 0}, {-1, -1}, {-2, -2}},     {{2, 3}, {0, 0}, {-1, -1}, {-1, -1}},
       {{2, 3}, {0, 0}, {-1, -1}, {0, 1}},       {{2, 3}, {0, 0}, {-1, -1}, {2, 4}},
       {{2, 3}, {0, 0}, {0, 1}, {-2, -2}},       {{2, 3}, {0, 0}, {0, 1}, {-1, -1}},
       {{2, 3}, {0, 0}, {0, 1}, {2, 4}},         {{2, 3}, {0, 0}, {2, 4}, {-2, -2}},
       {{2, 3}, {0, 0}, {2, 4}, {-1, -1}},       {{2, 3}, {0, 0}, {2, 4}, {0, 1}},
       {{2, 3}, {0, 0}, {2, 4}, {2, 4}},         {{2, 3}, {2, 4}, {-2, -2}, {-2, -2}},
       {{2, 3}, {2, 4}, {-2, -2}, {-1, -1}},     {{2, 3}, {2, 4}, {-2, -2}, {0, 0}},
       {{2, 3}, {2, 4}, {-2, -2}, {2, 4}},       {{2, 3}, {2, 4}, {-1, -1}, {-2, -2}},
       {{2, 3}, {2, 4}, {-1, -1}, {-1, -1}},     {{2, 3}, {2, 4}, {-1, -1}, {0, 0}},
       {{2, 3}, {2, 4}, {-1, -1}, {2, 4}},       {{2, 3}, {2, 4}, {0, 0}, {-2, -2}},
       {{2, 3}, {2, 4}, {0, 0}, {-1, -1}},       {{2, 3}, {2, 4}, {0, 0}, {0, 1}},
       {{2, 3}, {2, 4}, {0, 0}, {2, 4}},         {{2, 3}, {2, 4}, {2, 4}, {-2, -2}},
       {{2, 3}, {2, 4}, {2, 4}, {-1, -1}},       {{2, 3}, {2, 4}, {2, 4}, {0, 0}}});
  // clang-format on
}

}  // namespace test
}  // namespace oneflow
